package com.dianping.cat.home.dependency.config.transform;

import com.dianping.cat.home.dependency.config.IEntity;
import com.dianping.cat.home.dependency.config.IVisitor;
import com.dianping.cat.home.dependency.config.entity.DomainConfig;
import com.dianping.cat.home.dependency.config.entity.EdgeConfig;
import com.dianping.cat.home.dependency.config.entity.NodeConfig;
import com.dianping.cat.home.dependency.config.entity.TopologyGraphConfig;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  14 */   private Stack<Object> m_objs = new Stack();

  private TopologyGraphConfig m_topologyGraphConfig;


  public DefaultMerger() {}

  public DefaultMerger(TopologyGraphConfig topologyGraphConfig) {
/*  22 */     this.m_topologyGraphConfig = topologyGraphConfig;
/*  23 */     this.m_objs.push(topologyGraphConfig);
  }


/*  27 */   public TopologyGraphConfig getTopologyGraphConfig() { return this.m_topologyGraphConfig; }



  protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  35 */     this.m_objs.push(to);
    from.accept(this);
/*  37 */     this.m_objs.pop();
  }


/*  41 */   protected void mergeDomainConfig(DomainConfig to, DomainConfig from) { to.mergeAttributes(from); }



/*  45 */   protected void mergeEdgeConfig(EdgeConfig to, EdgeConfig from) { to.mergeAttributes(from); }



/*  49 */   protected void mergeNodeConfig(NodeConfig to, NodeConfig from) { to.mergeAttributes(from); }



/*  53 */   protected void mergeTopologyGraphConfig(TopologyGraphConfig to, TopologyGraphConfig from) { to.mergeAttributes(from); }



  public void visitDomainConfig(DomainConfig from) {
/*  58 */     DomainConfig to = (DomainConfig)this.m_objs.peek();

/*  60 */     mergeDomainConfig(to, from);
/*  61 */     visitDomainConfigChildren(to, from);
  }


  protected void visitDomainConfigChildren(DomainConfig to, DomainConfig from) {}


  public void visitEdgeConfig(EdgeConfig from) {
/*  69 */     EdgeConfig to = (EdgeConfig)this.m_objs.peek();

/*  71 */     mergeEdgeConfig(to, from);
/*  72 */     visitEdgeConfigChildren(to, from);
  }


  protected void visitEdgeConfigChildren(EdgeConfig to, EdgeConfig from) {}


  public void visitNodeConfig(NodeConfig from) {
/*  80 */     NodeConfig to = (NodeConfig)this.m_objs.peek();

/*  82 */     mergeNodeConfig(to, from);
/*  83 */     visitNodeConfigChildren(to, from);
  }

  protected void visitNodeConfigChildren(NodeConfig to, NodeConfig from) {
/*  87 */     for (DomainConfig source : from.getDomainConfigs().values()) {
/*  88 */       DomainConfig target = to.findDomainConfig(source.getId());

/*  90 */       if (target == null) {
/*  91 */         target = new DomainConfig(source.getId());
/*  92 */         to.addDomainConfig(target);
      }

      this.m_objs.push(target);
/*  96 */       source.accept(this);
/*  97 */       this.m_objs.pop();
    }
  }


  public void visitTopologyGraphConfig(TopologyGraphConfig from) {
/* 103 */     TopologyGraphConfig to = (TopologyGraphConfig)this.m_objs.peek();

/* 105 */     mergeTopologyGraphConfig(to, from);
/* 106 */     visitTopologyGraphConfigChildren(to, from);
  }

  protected void visitTopologyGraphConfigChildren(TopologyGraphConfig to, TopologyGraphConfig from) {
/* 110 */     for (NodeConfig source : from.getNodeConfigs().values()) {
/* 111 */       NodeConfig target = to.findNodeConfig(source.getType());

/* 113 */       if (target == null) {
/* 114 */         target = new NodeConfig(source.getType());
/* 115 */         to.addNodeConfig(target);
      }

/* 118 */       this.m_objs.push(target);
/* 119 */       source.accept(this);
/* 120 */       this.m_objs.pop();
    }

/* 123 */     for (EdgeConfig source : from.getEdgeConfigs().values()) {
/* 124 */       EdgeConfig target = to.findEdgeConfig(source.getKey());

/* 126 */       if (target == null) {
/* 127 */         target = new EdgeConfig(source.getKey());
/* 128 */         to.addEdgeConfig(target);
      }

/* 131 */       this.m_objs.push(target);
/* 132 */       source.accept(this);
/* 133 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/dependency/config/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */